package com.budwk.app.sqfwV2.generator.educationalInstitution;


import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.budwk.app.sqfwDoc.codeGenerator.pdfGenerate.SqfwPdfCreateCommonBO;
import com.budwk.app.sqfwDoc.codeGeneratorV2.fileParam.CommonParam;
import com.budwk.app.sqfwDoc.codeGeneratorV2.fileParam.ExcelGenerateParam;
import com.budwk.app.sqfwDoc.codeGeneratorV2.fileParam.ExcelRowDataParam;
import com.budwk.app.sqfwDoc.codeGeneratorV2.generate.BaseExcelGenerator;
import com.budwk.app.sqfwDoc.codeGeneratorV2.generate.ResultOfExcelDataInto;
import com.budwk.app.sqfwV2.dto.EducationalInstitutionDTO;
import com.budwk.app.sqfwV2.dto.LandscapePatrolDTO;
import com.budwk.app.sqfwV2.dto.image.AuthenticRightConfigBo;
import com.budwk.app.sqfwV2.enums.EducationalInstitutionEnums;
import com.budwk.app.sqfwV2.enums.LandscapePatrolEnum;
import com.budwk.app.sys.models.Sys_user;
import com.budwk.app.sys.services.SysUserService;
import com.budwk.app.util.poiUtils.excelPictureConfigBO.ExcelFileCreateParamBO;
import com.budwk.app.util.poiUtils.nutzBeanUtils.NutzIocUtils;
import com.budwk.starter.security.utils.SecurityUtil;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import static com.budwk.app.util.poiUtils.CommonFormOfficeUtils.addPictureToByteList;

public class EducationalInstitutionExcelGenerator extends BaseExcelGenerator {

    private String templateName;



    public EducationalInstitutionExcelGenerator(){}

    public EducationalInstitutionExcelGenerator(String templateName){
        this.templateName=templateName;
    }





    public boolean pdfCreateConditionCheck(SqfwPdfCreateCommonBO pdfDTO) {
        return true;
    }


    @Override
    protected void customerPopularHeaderData(Map<String, Object> excelParam, ExcelGenerateParam excelGenerateParam) {

        SysUserService sysUserService = NutzIocUtils.getBean(SysUserService.class);
        Sys_user user=sysUserService.getUserById(SecurityUtil.getUserId());
        excelParam.put("district",user.getDistrict());
        excelParam.put("county",user.getCounty().equals("直属")?"":user.getCounty());
        excelParam.put("community",user.getCommunity().equals("直属")?"":user.getCommunity());
        excelParam.put("downDate",DateUtil.format(new Date(),"yyyy年MM月dd日"));
    }

    @Override
    protected void customerPopularHeaderDataForAdmin(Map<String, Object> excelParam, ExcelGenerateParam excelGenerateParam) {

    }

    @Override
    protected ResultOfExcelDataInto judgeExcelHaveDataBeforeErgodic(Map<String, Object> excelParam, ExcelGenerateParam excelGenerateParam) {
        return null;
    }

    @Override
    protected boolean addRowDataCondition(ExcelRowDataParam rowDataParam, ExcelGenerateParam excelGenerateParam) {
        return true;
    }

    @Override
    protected void customerPopularSheetData(List<Map<String, Object>> listMap, ExcelGenerateParam excelGenerateParam) {

    }

    @Override
    protected void customerPopularRowDataMap(Map<String, Object> rowDataMap, ExcelRowDataParam rowDataParam) {
        EducationalInstitutionDTO educationalInstitutionDTO = (EducationalInstitutionDTO) rowDataParam.getAbstractCustomerPdfCreateField();
        if(StrUtil.isNotEmpty(educationalInstitutionDTO.getPropertyNature())){
            rowDataMap.put("var1","商业".equals(educationalInstitutionDTO.getPropertyNature())?"√":"");
            rowDataMap.put("var2","小区住房".equals(educationalInstitutionDTO.getPropertyNature())?"√":"");
        }
        if(StrUtil.isNotEmpty(educationalInstitutionDTO.getEducationalContent())){
            rowDataMap.put("var3","学科类".equals(educationalInstitutionDTO.getEducationalContent())?"√":"");
            rowDataMap.put("var4","非学科类".equals(educationalInstitutionDTO.getEducationalContent())?"√":"");
        }
        if(StrUtil.isNotEmpty(educationalInstitutionDTO.getLicenseSituation())){
            rowDataMap.put("var5","有照无证".equals(educationalInstitutionDTO.getLicenseSituation())?"√":"");
            rowDataMap.put("var6","无证无照".equals(educationalInstitutionDTO.getLicenseSituation())?"√":"");
        }

    }

    @Override
    protected void customerPopularRowDataMapForAdmin(Map<String, Object> rowDataMap, ExcelRowDataParam rowDataParam) {

    }

    @Override
    protected ResultOfExcelDataInto judgeExcelHaveDataBeforeCreate(Map<String, Object> excelParam, ExcelGenerateParam excelGenerateParam) {
        return null;
    }

    @Override
    protected String getTemplatePath(ExcelGenerateParam excelGenerateParam) {
        return this.templateName;
    }

    @Override
    protected String getDownloadFileName(ExcelGenerateParam excelGenerateParam) {
        String code = excelGenerateParam.getExcelConfig().getFileIdentity();
        return EducationalInstitutionEnums.getFileName(Integer.parseInt(code));
    }

    @Override
    protected Class<?> getImageConfigBO() {
        return AuthenticRightConfigBo.class;

    }

    @Override
        protected void completeExcelFileCreateParam(ExcelFileCreateParamBO excelFileCreateParamBO) {
            excelFileCreateParamBO.setImgWidth(180);
            excelFileCreateParamBO.setRowHeight(122);
        }


}
